package com.sitech.ibnms.core;

import java.lang.reflect.InvocationTargetException;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;

import com.opensymphony.xwork2.ActionContext;
import com.sitech.BaseConst;
import com.sitech.portal.system.domain.TblSYS_LOGINMSG;

/**
 * 此方法用于拦截currentUser对象，确保引用调用方法时，实际调用的是当前session中的SysUserBean的方法
 *
 * @author liujhc <liujhc@si-tech.com.cn>
 */
public class CurrentUserProxy {

	private TblSYS_LOGINMSG getCurrentUser() {
		return (TblSYS_LOGINMSG) ActionContext.getContext().getSession().get(BaseConst.SESSION_USER_KEY);
	}

	public Object proxy(ProceedingJoinPoint jp) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		//获取方法签名
		MethodSignature signature = (MethodSignature) jp.getSignature();
		//执行当前用户的对应方法
		return signature.getMethod().invoke(getCurrentUser(), jp.getArgs());
	}
}
